"""Set MIAME


.. helpdoc::
Expression set objects are typically annotated following the standards of MIAME.  These standards include requirements for annotating the experiment name, lab, title, contact, etc.  This widget allows users the opportunity to add this data into the eSet so that it can be saved and shared (thought this might be better done by simply sharing the Red-R saved session).  

"""


"""<widgetXML>
    <name>
        Set MIAME
    </name>
    <icon>
        default.png
    </icon>
    <summary>
        Set MIAME
    </summary>
    <tags>
        <tag priority="10">
            Bioinformatics
        </tag>
    </tags>
    <author>
        <authorname>Kyle R. Covington</authorname>
        <authorcontact>kyle@red-r.org</authorcontact>
    </author>
    </widgetXML>
"""

from OWRpy import * 
import redRGUI, signals

class miameData(OWRpy):
    globalSettingsList = ['commit']
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.RFunctionParam_expression = ''
        
        """.. rrsignals::
            :description: `A data table read in by the widget`"""
        self.inputs.addInput('id0', 'object', signals.affy.ESet, self.processobject)
        
        redRGUI.base.widgetLabel(self.controlArea, label = "Adds annation data to an eSet.  This adds to the signal data transparently.")
        self.param_name = redRGUI.base.lineEdit(self.controlArea, label = "Name")
        self.param_lab = redRGUI.base.lineEdit(self.controlArea, label = "Lab")
        self.param_contact = redRGUI.base.lineEdit(self.controlArea, label = "Contact")
        self.param_title = redRGUI.base.lineEdit(self.controlArea, label = "Title")
        self.param_abstract = redRGUI.base.lineEdit(self.controlArea, label = "Abstract")
        self.param_url = redRGUI.base.lineEdit(self.controlArea, label = "URL")
        self.param_other = redRGUI.base.lineEdit(self.controlArea, label = "Other")
        redRGUI.base.commitButton(self.bottomAreaRight, label = "Commit", callback = self.commitFunction)
    def processobject(self, data):
        if data:
            self.RFunctionParam_object=str(data.getData())
        else: self.RFunctionParam_object = ''
    def commitFunction(self):
        if self.RFunctionParam_object == '': return
        inj = []
        if self.param_abstract.text() != '': inj.append(', abstract = "%s"' % self.param_abstract.text())
        if self.param_contact.text() != '': inj.append(', contact = "%s"' % self.param_contact.text())
        if self.param_lab.text() != '': inj.append(', lab = "%s"' % self.param_lab.text())
        if self.param_name.text() != '': inj.append(', name = "%s"' % self.param_name.text())
        if self.param_title.text() != '': inj.append(', title = "%s"' % self.param_title.text())
        if self.param_url.text() != '': inj.append(', url = "%s"' % self.param_url.text())
        if self.param_other.text() != '': inj.append(', other = list(%s)' % self.param_other.text())
        if len(inj) == 0: return
        self.R('experimentData(%(data)s)<-new("MIAME", $(settings)s)' % {'data':self.RFunctionParam_object, 'settings':''.join(inj)}, wantType = redR.NOCONVERSION)
        self.status.setText('Data added to set')